package com.atgugu.realtime.util;

import com.atgugu.realtime.app.annotation.NoSink;
import com.atgugu.realtime.bean.ProductStats;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/12/31 15:36
 */
public class BeanUtil {
    // 返回这个类中所有的属性名
    public static <T> List<String> getFieldsNames(Class<T> tClass) {
        ArrayList<String> list = new ArrayList<>();
    
        Field[] fields = tClass.getDeclaredFields();
        for (Field field : fields) {
            NoSink noSink = field.getAnnotation(NoSink.class);
            if (noSink == null) {
                String name = field.getName();
                list.add(name);
            }
        }
    
        return list;
    }
    
    public static void main(String[] args) {
        List<String> list = getFieldsNames(ProductStats.class);
        for (String s : list) {
            System.out.println(s);
        }
    }
}
